package cn.practice._06interceptor.interceptors;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器的类,实现HandlerInterceptor接口
 */
@Slf4j
public class MyInterceptor1 implements HandlerInterceptor {
    /*
    请求校验处理器方法之前执行此方法
    @Param request 请求对象
    @Param response 响应对象
    @Param handler 处理器对象
    @return 返回true表示放行,返回false表示拦截
    @Throws Exception  异常对象
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       log.debug("1.第一个拦截器的preHandle执行");
       return true;
//        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
    /*
    请求校验处理器方法之后执行此方法，对响应进行处理：比如敏感词过滤
    @Param request 请求对象
    @Param response 响应对象
    @Param handler 处理器对象
    @Param modelAndView 模型视图对象
    @Throws Exception  异常对象
     */

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.debug("2.第一个拦截器的postHandle执行");
//        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.debug("3.第一个拦截器的afterCompletion执行");
        //        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
    }
}
